<extend name="Public/base"/>
<block name="content">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">一币抽奖</strong>  <small></small></div>
            </div>

            <hr>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{:U('reward/add_lottery')}" type="button" class="am-btn am-btn-primary"><span class="am-icon-plus"></span> 新增</a>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12">
                    <!--<form class="am-form">-->
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <!--<th class="table-id">序号</th>-->
                                <th class="table-title">抽奖期号</th>
                                <th class="table-url">满标标数</th>
                                <th class="table-type">已投标数</th>
                                <th class="table-type">奖品</th>
                                <th class="table-set">奖品价值(USDT)</th>
                                <th class="table-type">状态</th>
                                <th class="table-type">开启时间</th>
                                <th class="table-type">结束时间</th>
                                <th class="table-type">开奖时间</th>
                                <!--<th class="table-type">是否补标</th>-->
                                <th class="table-type">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--<tr>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                                <!--<td>1</td>-->
                            <!--</tr>-->
                            <volist name="data" id="vo">
                                <tr>
                                    <!--<td>{$key+1}</td>-->
                                    <td>第{$vo.lottery_id}期</td>
                                    <td>{$vo.mark_number}</td>
                                    <td>{$vo.already_biao}</td>
                                    <td>{$vo.award}</td>
                                    <td>{$vo.award_price}</td>
                                    <td>
                                        <if condition="$vo.status eq 0">
                                            已结束
                                            <elseif condition="$vo.status eq 1 and $vo.flag eq 0"/>
                                            活动中
                                            <elseif condition="$vo.status eq 2" />
                                            未开始
                                            <elseif condition="$vo.status eq 1 and $vo.flag eq 2"/>
                                            待开奖
                                            <else />
                                            流标
                                        </if>
                                    </td>
                                    <td>{$vo.start_time|date='Y-m-d H:i:s',###}</td>
                                    <td>{$vo.end_time|date='Y-m-d H:i:s',###}</td>
                                    <td>{$vo.lottery_time|date='Y-m-d H:i:s',###}</td>
                                    <!--<td>-->
                                        <!--<if condition="$vo.is_add_user eq 0">不补标 <else />补标</if>-->
                                    <!--</td>-->
                                    <td lottery="{$vo.lottery_id}" status="{$vo.status}" flag="{$vo.flag}" mark="{$vo.mark_number}" already="{$vo.already_biao}">
                                        <button class="btn am-btn-danger open_lottery" style="color: black">开奖</button>
                                        <button class="btn am-btn-danger bubiao" style="color: black">补标</button>
                                        <button class="btn am-btn-danger liubiao" style="color: black">流标</button>
                                        <button class="btn am-btn-danger is_fixed" style="color: black">设置中奖用户</button>
                                        <button class="btn am-btn-danger edit" lid="{$vo.id}" style="color: black">重新编辑</button>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    <!--</form>-->
                    <div class="am-cf">
                        共 {$count} 条记录
                        <div class="am-fr">
                            <ul class="am-pagination">
                                {$show}
                            </ul>
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
</block>
<block name="js">
    <script src="__COMMON__/js/jquery.min.js"></script>
    <script>
        $(".edit").click(function () {
            $id=$(this).attr('lid');
            window.location.href="{:U('add_lottery')}?id="+$id;
        })
        $(".is_fixed").click(function () {
            $lottery_id=$(this).parent().attr('lottery');
            $already=$(this).parent().attr('already');
            layer.open({
                type: 1,
                title: "指定中奖用户",
                shadeClose: true,
                shade: 0.4,
                area: ['50%', '50%'],
                content: '<div>\n' +
                    '          <p>您将指定第'+$lottery_id+'期抽奖</p>\n' +
                    '          <p>已投标数：'+$already+'枚</p>\n' +' <label for="">账户昵称：</label>'+
                    '          <input type="text" placeholder="输入账户昵称" id="username">\n' +
                    '      </div>',
                btn: ['确定','关闭'],
                yes: function(index){
                    //当点击‘确定’按钮的时候，获取弹出层返回的值
                    //打印返回的值，看是否有我们想返回的值。
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url:"{:U('fixed')}",
                        data:{
                            lottery_id:$lottery_id,
                            username:$("#username").val(),
                        },
                        success:function (data) {
                            if(data.code>0){
                                alert(data.message);
                                window.location.reload();
                            }else {
                                alert(data.message);
                                return false;
                            }

                        }
                    })
                    //最后关闭弹出层
                    layer.close(index);
                },
                cancel: function(){
                    //右上角关闭回调
                }
            });
        })

        $(".open_lottery").click(function () {
            $status=$(this).parent().attr('status');
            $already=$(this).parent().attr('already');
            $mark=$(this).parent().attr('mark');
            $lottery_id=$(this).parent().attr('lottery');
            $flag=$(this).parent().attr('flag');
            if($status==0){
                alert('活动已结束');return false;
            }
            if($status==2){
                alert('活动未开始');return false;
            }
            if($status==3){
                alert('活动已流标');return false;
            }
            if($status==1&&$flag==2){
                alert('活动已满标，待开奖中');return false;
            }
                if(confirm('该期抽奖活动还未满标，确定要强行开奖吗')){
                    $.ajax({
                        type:"post",
                        dataType:"json",
                         url:"{:U('open_lottery')}",
                        data:{
                            lottery_id: $lottery_id,
                        },
                        success:function (data) {
                            alert(data.msg);
                        }
                    })
                }else {
                    return false;
                }
                    

        })
        
        $(".bubiao").click(function () {
            $status=$(this).parent().attr('status');
            $already=$(this).parent().attr('already');
            $mark=$(this).parent().attr('mark');
            $lottery_id=$(this).parent().attr('lottery');
            $flag=$(this).parent().attr('flag');
            if($status==0){
                alert('活动已结束');return false;
            }
            if($status==2){
                alert('活动未开始');return false;
            }
            if($status==3){
                alert('活动已流标');return false;
            }
            if($status==1&&$flag==2){
                alert('活动已满标，待开奖中');return false;
            }
            layer.open({
                type: 1,
                title: "补标账户",
                shadeClose: true,
                shade: 0.4,
                area: ['50%', '50%'],
                content: '<div>\n' +
                    '          <p>您将补标第'+$lottery_id+'期抽奖</p>\n' +
                    '          <p>满标标数：'+$mark+'枚</p>\n' +
                    '          <p>已投标数：'+$already+'枚</p>\n' +' <label for="">账户昵称：</label>'+
                    '          <input type="text" placeholder="输入账户昵称" id="username">\n' +
                    '      </div>',
                btn: ['确定','关闭'],
                yes: function(index){
                    //当点击‘确定’按钮的时候，获取弹出层返回的值
                    //打印返回的值，看是否有我们想返回的值。
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url:"{:U('bubiao')}",
                        data:{
                            lottery_id:$lottery_id,
                            username:$("#username").val(),
                        },
                        success:function (data) {
                            if(data.code>0){
                                alert(data.msg);
                                window.location.reload();
                            }else {
                                alert(data.msg);
                                return false;
                            }

                        }
                    })
                    //最后关闭弹出层
                    layer.close(index);
                },
                cancel: function(){
                    //右上角关闭回调
                }
            });
        })

        $(".liubiao").click(function () {
            $status=$(this).parent().attr('status');
            $already=$(this).parent().attr('already');
            $mark=$(this).parent().attr('mark');
            $lottery_id=$(this).parent().attr('lottery');
            $flag=$(this).parent().attr('flag');
            if($status==0){
                alert('活动已结束');return false;
            }
            if($status==2){
                alert('活动未开始');return false;
            }
            if($status==3){
                alert('活动已流标');return false;
            }
            if($status==1&&$flag==2){
                alert('活动已满标，待开奖中');return false;
            }

            if(confirm('时间还未到期，确定要强行流标吗')){
                $.ajax({
                    type:"post",
                    dataType:"json",
                    url:"{:U('liubiao')}",
                    data:{
                        lottery_id:$lottery_id,
                    },
                    success:function (data) {
                        alert(data.msg);
                        window.location.reload();
                    }
                })
            }
        })
    </script>
</block>